// pages/pay/pay.js
var openid;
var deivceid;
var orderid;
var unionid;
var total;
var hotel;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    items:[
    ],
    hotl:"",
    jgs:"",
    times:"",
    catalogSelect:"",
    noid:''
  },
  chooseCatalog: function (data) {
    var that = this;
    that.setData({//把选中值放入判断值
      catalogSelect: data.currentTarget.dataset.select,
      jgs: data.currentTarget.dataset.jgs,
      times: data.currentTarget.dataset.times
    })


  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.currentTarget.dataset.value + deivceid + orderid + hotel + unionid);
    var ss = e.currentTarget.dataset.value;
    if(ss!=","){
      ss = ss.split(",");
      console.log(openid);
      console.log(ss[1]);
      wx.request({
        url: 'https://wwgxwx.arksh.com/api/wxpay/wxpay',
        data: {
          openid: openid,
          sum: ss[0],
          nid: 35,
        },
        success(res) {
          console.log(res);
          orderid = res.data.orderid
          wx.requestPayment({
            timeStamp: res.data.timeStamp,
            nonceStr: res.data.nonceStr,
            package: res.data.package,
            signType: 'MD5',
            paySign: res.data.paySign,
            success(res) {
              var timestamps = Date.parse(new Date());
              wx.request({
                url: 'https://wwcxc.arksh.com/api/port/shareBenefit',
                data: {
                  type: 1,
                  deviceid: deivceid,
                  order: orderid,
                  sum: ss[0],
                  hotel: hotel,
                  nid: 35,
                  unionid: unionid,
                  total: ss[1]

                },
                success(res) {
                  console.log(res);
                  if (res.data.ret == 0) {
                    wx.reLaunch({
                      url: '/pages/index/index?scene=' + deivceid
                    })
                  }
                }
              })
            },
            fail(res) { }
          });
        }
      })
    }else{
      wx.showToast({
        title: '请先选择价格',
        icon: 'none',
        duration: 2000
      })
    }

    
    // wx.faceVerifyForPay({
    //   scene:1,
    //   package:'2.0',
    //   packageSign:'ewrvfewfds',
    //   otherVerifyTitle:'woridng',
    //   success(res){
    //     console.log(res);
    //   },
    //   fail(res){
    //     console.log(res);
    //   },
    //   complete(res){
    //     console.log(res);
    //   }
    // });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var value = wx.getStorageSync('userInfo');
    openid = options.openid;
    unionid = value.unionid;
    var that = this;
    console.log(options);
    //获取设备所在酒店
    deivceid = options.device;
    var hot = options.hotel;
    hotel = options.hotels;
    var noid = options.devices;
   if(noid=="null"){
     noid=  "";
   }
       console.log(hot);
    //hotelId =7
    console.log("设备号:" + deivceid)
      //根据酒店编号，获取价格
    wx.request({
      url: 'https://wwcxc.arksh.com/api/xcx/hotelRrice', //仅为示例，并非真实的接口地址
      data: {
        deivceid: deivceid,
        nid: 35,
      },
      success(res) {
        console.log("价格：" + JSON.stringify(res))
        var ret = res.data.ret;
        if(ret==0){
          that.setData({
            items: res.data.data,
            noid:noid,
            hotl:hot
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 5000
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})